<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('流程任务驳回')" />
    <style type="text/css">
        .layui-input, .layui-textarea{width: 85%;}
        .layui-form-label{width:160px}
        .layui-form-select dl{margin-left:12%;min-width:80%;}
        .layui-edge{margin-right:7%}
    </style>
</head>
<body>
<form class="layui-form" id="form-task-reject" style="padding: 16px 84px 16px 25px;">
    <input type="hidden" id="taskId" name="taskId" th:value="${taskId}">
    <input type="hidden" id="tableDataId" name="tableDataId" th:value="${tableDataId}">
    <input type="hidden" id="optType" name="optType" value="reject">
    <div class="layui-form-item">
        <label class="layui-form-label">任务主题：</label>
        <div class="layui-input-block">
            <input type="text" id="taskName" autocomplete="off" class="layui-input canntEdit" readonly th:value="${processTitle} +'－['+ ${taskName} +']'">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">紧迫程度：</label>
        <div class="layui-input-block">
            <input type="radio" name="priority" value="1" title="一般" th:checked="${taskPriority == 1}">
            <input type="radio" name="priority" value="2" title="重要" th:checked="${taskPriority == 2}">
            <input type="radio" name="priority" value="3" title="紧急" th:checked="${taskPriority == 3}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">简短附言：</label>
        <div class="layui-input-block">
            <textarea id="comment" name="comment" class="layui-textarea" placeholder="请输入内容" style="height:100px;"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><font class="f_red">*</font>驳回至：</label>
        <div class="layui-input-block">
            <select type="text" id="activityId" name="activityId"  autocomplete="off" class="layui-select"  lay-filter="select" th:with="map=${activityList}">
                <option th:each="item : ${map}" th:text="${item.name}" th:value="${item.key}"></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item" style="margin-bottom: 0px;">
        <label class="layui-form-label">执行者：</label>
        <div class="layui-input-block">
            <div  style="padding-right:15px;float:left;">
                <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit="" lay-filter="btn_save" id="btn_save" value="提交">
    </div>
</form>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    /*<![CDATA[*/
    var prefix = ctx + "flowable/task";
    var jumpUrl = [[${jumpUrl}]];
    /*]]>*/
</script>
<script th:inline="javascript">
    var listData=[];
    var $,layer,form;
    layui.use(['layer','jquery','util','element','form','table'], function () {
        $ = layui.$,layer = layui.layer,util = layui.util,element=layui.element,form=layui.form,table=layui.table;
        selectActivity();
        $.tablelist.init({
            elem: '#dhtable'
            ,data: listData
            ,page:false
            ,limit:10000
            ,width:490
            ,cols: [[
                {type:'numbers',title:''},
                {field: 'userId',title: '员工编号',width:120},
                {field: 'userName',title: '员工姓名',width:130},
                {field: 'deptId',title: '部门编号',hide:true},
                {field: 'deptName',title: '所属部门',width:180}
            ]
            ]
            ,defaultToolbar:[]
            ,height:200
        });
        form.on('select(select)', function(data){
            selectActivity();
        });
    });
    //提交调用的方法
    function processTaskCallback() {
        if ($.validate.form()) {
            var data =  $.common.formToJSON('form-task-reject');
            var tableData = table.cache.dhtable;
            if(tableData.length == 0){
                $.modal.alert("请选择驳回环节执行者！", modal_status.FAIL);
            }else{
                var assignees = [];
                for (var i=0;i<tableData.length;i++){
                    var rowData = tableData[i];
                    assignees.push(rowData.userId);
                }
                data.assignees = assignees.join(",");
                if(data.medium ==  null){
                    data.medium = "";
                }
                return {'url':ctx + jumpUrl, 'data':data};
            }
        }
    }
    function selectActivity(){
        var taskId = $("#taskId").val();
        var activityId = $("#activityId").val();
        var rejectActUserUrl = prefix + "/getRejectActUser";
        table.reload('dhtable', {data:[]});
        $.post(rejectActUserUrl,{taskId:taskId, activityId:activityId}, function(rec){
            if(rec.code == 0){
                listData = rec.data;
                table.reload('dhtable', {data:listData});
            }else {
                $.modal.alert(rec.msg, modal_status.FAIL)
            }
        });
    }
</script>
</body>
</html>